package com.jt.controller;

import com.jt.entity.Request;
import com.jt.entity.Response;
import com.jt.entity.SideBar;
import com.jt.service.SidebarNodeService;
import com.jt.util.JsonTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Administrator on 2017/3/31.
 */
@RestController
public class HttpController {

    private static Logger logger = LoggerFactory.getLogger(HttpController.class);

    @Autowired
    private JsonTemplate jsonTemplate;

    @Autowired
    private SidebarNodeService sidebarNodeService;

    @RequestMapping(value = "/json")
    public Response json(@RequestBody Request<Object> request) {
        System.out.println(jsonTemplate.java2JsonStr(request));
        return Response.success("处理成功！");
    }

    @RequestMapping(value = "/post")
    public Response post(@RequestParam("request") String request) {
        logger.info(request);
        System.out.println(jsonTemplate.jsonStr2Java(request, Request.class));
        return Response.success("处理成功！");
    }

    @RequestMapping(value = "/sidebar")
    public SideBar sideBar() {
        return sidebarNodeService.getSideBar();
    }

}
